﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace DevIsMagic.ViewModel
{
	[System.Xml.Serialization.XmlRoot(ElementName="ColumnsPrefs")]
	public class ColumnViewModelCollection : ObservableCollection<ColumnViewModel>, INotifyPropertyChanged
	{
		/*protected override void InsertItem(int index, ColumnViewModel item)
		{
			base.InsertItem(index, item);
			item.PropertyChanged += new PropertyChangedEventHandler(item_PropertyChanged);
		}

		protected override void RemoveItem(int index)
		{
			var item = this.Items[index];
			base.RemoveItem(index);
			item.PropertyChanged -= new PropertyChangedEventHandler(item_PropertyChanged);
		}

		protected override void SetItem(int index, ColumnViewModel item)
		{
			var oldItem = this.Items[index];
			oldItem.PropertyChanged -= new PropertyChangedEventHandler(item_PropertyChanged);
			if (!this.Items.Contains(item))
			{
				item.PropertyChanged += new PropertyChangedEventHandler(item_PropertyChanged);
			}
			base.SetItem(index, item);
		}
		void item_PropertyChanged(object sender, PropertyChangedEventArgs e)
		{
			ForwardPropertyChanged(sender, e);
		}

		#region INotifyPropertyChanged Members

		public event PropertyChangedEventHandler PropertyChanged;

		protected virtual void ForwardPropertyChanged(object sender, PropertyChangedEventArgs e)
		{
			if (PropertyChanged != null) PropertyChanged(sender, e);
		}
		#endregion*/
	}
	public class ColumnViewModel : ViewModelBase
	{
		private object m_header;
		public object Header { get { return m_header; }
			set
			{
				if (value != m_header)
				{
					m_header = value;
					RaisePropertyChanged("Header");
				}
			}
		}
		private bool m_visible = true;
		public bool Visible
		{
			get { return m_visible; }
			set
			{
				if (value != m_visible)
				{
					m_visible = value;
					RaisePropertyChanged("Visible");
				}
			}
		}
		private string m_memberName;
		public string MemberName
		{
			get { return m_memberName; }
			set
			{
				if (value != m_memberName)
				{
					m_memberName = value;
					RaisePropertyChanged("MemberName");
				}
			}
		}
		private double m_width = double.NaN;

		public double Width
		{
			get { return m_width; }
			set {
				if (value != m_width)
				{
					m_width = value;
					RaisePropertyChanged("Width");
				}
			}
		}

		public ColumnViewModel() : base()
		{
		}
		
	}
}
